<?php


namespace app\common\models;


use app\common\traits\BaseModelOptionTrait;
use Carbon\Carbon;
use think\Model;

class UserRecharge extends Model
{
    use BaseModelOptionTrait;

    const PAY_NOTPAY = 1;
    const PAY_SUCCESS = 2;
    const PAY_FAIL = 3;

    // 支付平台
    const PAY_WAY_WECHAT = 1;

    protected $table = 'xiangji_user_recharge';

    public static function onBeforeInsert(Model $model)
    {
        $model->order_no = 'CZ' . Carbon::now()->format('YmdHis') . mt_rand(1000000000, 9999999999);
    }

    public function log()
    {
        return $this->hasOne(UserRechargeLog::class, 'order_no', 'order_no');
    }
}
